﻿using System;
using System.Windows.Forms;

namespace XwOa
{
    public partial class FrmAutoSign : Form
    {
        public FrmAutoSign()
        {
            InitializeComponent();
        }

        public bool IsSet { get; set; }

        public string UserName
        {
            get { return txtUserName.Text; }
            set { txtUserName.Text = value; }
        }

        public string Password
        {
            get { return txtPwd.Text; }
            set { txtPwd.Text = value; }
        }

        public bool AutoSign
        {
            get { return chkAutoSign.Checked; }
            set { chkAutoSign.Checked = value; }
        }

        public TimeSpan AmSignIn
        {
            get { return dtpAmSignIn.Value.TimeOfDay; }
            set { dtpAmSignIn.Text = value.ToString(); }
        }

        public TimeSpan AmSignOut
        {
            get { return dtpAmSignOut.Value.TimeOfDay; }
            set { dtpAmSignOut.Text = value.ToString(); }
        }

        public TimeSpan PmSignIn
        {
            get { return dtpPmSignIn.Value.TimeOfDay; }
            set { dtpPmSignIn.Text = value.ToString(); }
        }

        public TimeSpan PmSignOut
        {
            get { return dtpPmSignOut.Value.TimeOfDay; }
            set { dtpPmSignOut.Text = value.ToString(); }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUserName.Text))
            {
                Warning("请填写用户名");
                return;
            }

            if (string.IsNullOrWhiteSpace(txtPwd.Text))
            {
                Warning("请填写密码");
                return;
            }

            if (AmSignIn < AmSignOut && AmSignOut < PmSignIn && PmSignIn < PmSignOut)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                Warning("签退时间必须大于签到时间");
            }
        }

        private void FrmAutoSign_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (IsSet || DialogResult == DialogResult.OK)
            {
                return;
            }

            e.Cancel = true;
            Warning("请先完善程序配置");
        }

        private static void Warning(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}
